home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
FIX_DESK
/
SOURCE
/
COMMENTS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-09-07
|
3KB
|
164 lines
#include <MacTypes.h>
#include <ResourceMgr.h>
#include "fix.h"
/* Local types. */
typedef struct fcmt_node {
struct fcmt_node *next;
int number;
} fcmt_node, *fcmt_ptr, *fcmt_table[HASH_SIZE];
static fcmt_table comment_table;
/* Local prototypes. */
int hash(int number);
void insert_fcmt(int number);
/* Hash an FCMT index into the hash table range. */
static int hash(number)
int number;
{
if (number < 0)
number = -number;
return(number % HASH_SIZE);
}
/* Insert an FCMT record into the hash table. */
static void insert_fcmt(number)
int number;
{
register long hash_value = hash(number);
register fcmt_ptr temp = (fcmt_ptr) NewPtr((long) sizeof(fcmt_node));
temp->next = comment_table[hash_value]; /* Insert at */
temp->number = number; /* beginning of */
comment_table[hash_value] = temp; /* hash list... */
}
/* Remove an FCMT record from the hash table. */
void remove_fcmt(number)
int number;
{
register long hash_value = hash(number);
register fcmt_ptr temp, prev;
temp = comment_table[hash_value];
prev = NIL;
while ((temp) && (temp->number != number)) {
prev = temp;
temp = temp->next;
}
if (temp) { /* Found it... */
if (!prev) /* Unlink from chain... */
comment_table[hash_value] = temp->next;
else
prev->next = temp->next;
DisposPtr(temp);
}
}
/* Hash a filename to an MFS comment ID (like the Finder). */
/* The filename MUST be in Pascal format!!! */
int comment_hash(name)
register unsigned char *name;
{
register int value;
asm {
moveq #0,d0
move.b (name)+,d0
moveq #0,value
@1 move.b (name)+,d1
eor.b d1,value
ror.w #1,value
bmi.s @2
neg.w value
@2 subq.w #1,d0
bne.s @1
}
return (value);
}
/* Perform initial comment processing. */
void pre_comment_processing()
{
register int i, count;
/* Empty the hash table. */
{
register fcmt_ptr *p;
comment_count = 0;
p = &comment_table[0];
for (i=0; i<HASH_SIZE; i++, p++) /* Clear hash table... */
*p = NIL;
}
/* Insert all FCMT resources into the hash table. */
SetResLoad(0);
count = Count1Resources('FCMT');
for (i=1; i<=count; i++) {
register Handle hand;
int number;
long blob;
unsigned char name[LONG_NAME_SIZE];
hand = Get1IndResource('FCMT',i);
GetResInfo(hand,&number, &blob, &name);
ReleaseResource(hand);
insert_fcmt(number);
}
if (!is_hfs) {
count = Count1Resources('FOBJ'); /* Do folders... */
for (i=1; i<=count; i++) {
register Handle hand;
int number;
long blob;
unsigned char name[LONG_NAME_SIZE];
hand = Get1IndResource('FOBJ',i);
GetResInfo(hand, &number, &blob, &name);
ReleaseResource(hand);
remove_fcmt(comment_hash(name));
}
}
SetResLoad(1);
}
/* Perform final comment processing. */
void post_comment_processing()
{
register int i;
register fcmt_ptr *p;
/* For each entry left in the hash table, remove its FCMT resource. */
p = &comment_table[0];
for (i=0; i<HASH_SIZE; i++, p++) {
register fcmt_ptr temp, temp2;
temp = *p;
while (temp) {
comment_count++;
#ifndef TEST_MODE
kill_resource('FCMT', temp->number);
#endif TEST_MODE
temp2 = temp;
temp = temp->next;
DisposPtr(temp2);
}
}
}